from pyecharts import options as opts
from pyecharts.charts import Bar
import random

l1 = ['很长很长很长很长很长的坐标轴{}'.format(i) for i in range(10)]
l2 = [random.choice(range(10, 100, 10)) for i in range(10)]
bar = (
    Bar()
        .add_xaxis(l1)
        .add_yaxis("l2", l2)
        .set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),
                         # rotate=-15表示将坐标轴逆时针旋转15度
                         title_opts=opts.TitleOpts(title="Bar-旋转X轴标签", subtitle="解决标签名字过长的问题"))
)
bar.render(path='7.旋转x轴坐标.html')
